//
//  BundleloadEventEmiter.m
//  ocdemo
//
//  Created by mac on 2025/2/8.
//

#import "BundleloadEventEmiter.h"

@implementation BundleloadEventEmiter
{
    _Bool hasListeners;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bundleLoaded:) name:@"BundleLoad" object:nil];
    }
    return self;
}
RCT_EXPORT_MODULE();

- (void)startObserving{
    hasListeners=YES;
}
- (void)stopObserving{
    hasListeners=NO;
}
- (NSArray<NSString *> *)supportedEvents{
    return @[@"BundleLoad"];
}
-(void)bundleLoaded:(NSNotification *)notification{
    NSString * bundlePath=notification.userInfo[@"path"];
    if(hasListeners){
        [self sendEventWithName:@"BundleLoad" body:@{@"path":bundlePath}];
    }
}
@end
